home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
NoShitSherlock
/
NoShitSherlock.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-23
|
3KB
|
114 lines
#include <A4Stuff.h>
#include <Applescript.h>
#include <OSA.h>
typedef pascal void (*MaxApplZoneProcPtr)(void);
typedef pascal Boolean (*SystemEventProcPtr)(const EventRecord *);
typedef struct Stub {
ProcessSerialNumber psn;
SystemEventProcPtr patch;
} Stub, **StubHdl;
MaxApplZoneProcPtr saveMaxApplZone = 0;
StubHdl stubs = 0;
FSSpec spec;
static pascal Boolean MySystemEvent(EventRecord *event) {
long saveA4 = SetCurrentA4();
Boolean result = false;
long i, count;
Stub stub;
GetCurrentProcess(&stub.psn);
count = GetHandleSize((Handle) stubs) / sizeof(Stub);
for(i=0; i<count; i++) {
if ((stub.psn.highLongOfPSN == (*stubs)[i].psn.highLongOfPSN) &&
(stub.psn.lowLongOfPSN == (*stubs)[i].psn.lowLongOfPSN)) break;
}
if (i < count) {
if ((event->what == keyDown) &&
(event->modifiers & cmdKey) &&
(event->modifiers & optionKey)) {
LaunchParamBlockRec pb;
long i;
result = true;
event->what = nullEvent;
for(i=0; i<sizeof(pb); ((char *) &pb)[i++] = 0);
pb.launchBlockID = extendedBlock;
pb.launchEPBLength = extendedBlockLen;
pb.launchFileFlags = 0;
pb.launchControlFlags = launchNoFileFlags | launchContinue;
pb.launchAppSpec = &spec;
LaunchApplication(&pb);
}
else {
stub = (*stubs)[i];
result = (*stub.patch)(event);
}
}
SetA4(saveA4);
return(result);
}
static pascal void MyMaxApplZone() {
long saveA4 = SetCurrentA4();
Stub stub;
if (saveMaxApplZone) {
long i, count;
(*saveMaxApplZone)();
if (stubs && (*((short *) 0x0910) != 0x0000FFFF)) {
GetCurrentProcess(&stub.psn);
stub.patch = 0;
count = GetHandleSize((Handle) stubs) / sizeof(Stub);
for(i=0; i<count; i++) {
if ((stub.psn.highLongOfPSN == (*stubs)[i].psn.highLongOfPSN) &&
(stub.psn.lowLongOfPSN == (*stubs)[i].psn.lowLongOfPSN)) break;
}
if (i == count) {
SetHandleSize((Handle) stubs, (count+1) * sizeof(Stub));
if (!MemError()) {
if (stub.patch = (SystemEventProcPtr) NGetTrapAddress(_SystemEvent, ToolTrap)) {
NSetTrapAddress((ProcPtr) MySystemEvent, _SystemEvent, ToolTrap);
(*stubs)[count] = stub;
}
}
}
}
}
SetA4(saveA4);
}
void main() {
long saveA4 = SetCurrentA4();
Handle handle = 0;
FCBPBRec fcbpb;
long i;
if (stubs = (StubHdl) NewHandleSys(0)) {
if (handle = Get1Resource('INIT', 0)) {
DetachResource(handle);
for(i=0; i<sizeof(fcbpb); ((char *) &fcbpb)[i++] = 0);
fcbpb.ioVRefNum = -1;
fcbpb.ioRefNum = CurResFile();
fcbpb.ioNamePtr = spec.name;
if (!PBGetFCBInfoSync(&fcbpb)) {
spec.vRefNum = fcbpb.ioVRefNum;
spec.parID = fcbpb.ioFCBParID;
}
if (saveMaxApplZone = (MaxApplZoneProcPtr) NGetTrapAddress(_MaxApplZone, OSTrap))
NSetTrapAddress((ProcPtr) MyMaxApplZone, _MaxApplZone, OSTrap);
}
}
SetA4(saveA4);
}